import { _decorator, assetManager, AssetManager, BufferAsset, Component, find, ImageAsset, native, Node, Sprite, SpriteFrame, Texture2D, Vec3 } from 'cc';
import { GLOBALUtil } from './GlobalUtil';
import { ModifyPersonalDataManager } from './ModifyPersonalDataManager';
const { ccclass, property } = _decorator;

@ccclass('NewAvatarTest')
export class NewAvatarTest extends Component {
    @property({type:Node, tooltip: "修改头像面板"})
    private ModifyAvatarNode: Node = null;
    @property({type:Node, tooltip: "ModifyPersonalDataNode"})
    private ModifyPersonalDataNode: Node = null;
    start() {

    }

    update(deltaTime: number) {
        
    }

    showImg(base64Image){
        // 激活修改头像的面板
        this.ModifyPersonalDataNode.getComponent(ModifyPersonalDataManager).openModifyAvatarNode();
        console.log("Received Base64 Image: ", base64Image); // 打印日志
        let imgData = "data:image/png;base64," + base64Image; // 拼接 Base64 前缀
        const img = new Image();
        img.src = imgData;                    
        img.onload = () => {
            // 创建 ImageAsset 实例
            const imageAsset = new ImageAsset(img);
            const texture2d = new Texture2D();
            texture2d.image = imageAsset;
            const spriteFrame = new SpriteFrame();
            spriteFrame.texture = texture2d;
            this.node.getComponent(Sprite).spriteFrame = spriteFrame;
        };
    }
}


